Plex.Lib.JS.load("UI.Widget.Sky_Box");

/**
 * @class Simple widget for an extended prompt box
 * @requires Sky_Box
 * @inherits Sky_Box
 */
Sky_Option = Sky_Box.extend({
	/**
	 * @constructor
	 * @param {string} title Title For OptionBox
	 */
	initialize: function(title){
		this.parent();
		
		if(!title)
		title="Options";
		
		this.el.mainDiv = new Element("table", {
			'class':"Sky_Option",
			'cellpadding':0,
			'cellspacing':0,
		});
		
		this.el.headerTR = new Element("tr", {
			'class':"header",
		}).injectInside(this.el.mainDiv);
		
		this.el.headerTH = new Element("th", {
			'class':"header",
		}).setText(title).injectInside(this.el.headerTR);
		
		this.el.bodyTR = new Element("tr").injectInside(this.el.mainDiv);
		this.el.bodyTD = new Element("td").injectInside(this.el.mainDiv);
		
		this.el.bodyTBL = new Element("table", {
			'class':"Options",
			'cellpadding':1,
			'cellspacing':3,
		}).injectInside(this.el.bodyTD);
	},
	
	el: {
		
	},
	
	/* Sky_Option Settings */
	options: {
		
	},
	
	
	/**
	 * add option
	 * @param {string} title Title	 
	 * @param {function} handler Handler
	 * @param {char} title Hotkey in alphaNumeric
	 */
	addOption: function(title, handler, hotkey){
		var Rhandler = function(e){
			if(typeof handler == "string")
			window.location = handler;
			else if(handler)
			handler(e);
			self.close();
		}
		
		
		var self = this;		
		var newOptionTR = new Element("tr",{
			'class':'option',
			'events':{
				'click':Rhandler
			}
		}).injectInside(this.el.bodyTBL);
		var newOptionTD = new Element("td").setText(title).injectInside(newOptionTR);
		
		if(hotkey)
		this.options.hotKeys[hotkey] = Rhandler
	},
	
	/**
	 * Open Sky_Option
	 */
	open: function() {
		this.loadElement(this.el.mainDiv);		
		this.parent();
	},
	
	/**
	 * Close Sky_Option
	 */
	close: function(){
		this.parent();
		
	}
})
